package com.ygqh.baby.handler;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.SalesPlatform;
import com.ygqh.baby.model.YgShoppingCarModel;
import com.ygqh.baby.service.YgShoppingCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * 〈〉
 *
 * @author guohao
 * @date 2018/12/28 13:42
 * @since 1.0.0
 */
@Component
public class SettlementHandler extends BaseShoppingCarHandler {

    @Autowired
    private YgShoppingCarService ygShoppingCarService;

    public Message toSettlementPage(Long[] skuIds, Long userId, Boolean distribution) {
        return toSettlementPage(skuIds, userId, distribution, SalesPlatform.Yiigoo);
    }

    public Message toSettlementPage(Long[] skuIds, Long userId, Boolean distribution, SalesPlatform salesPlatform) {
        List<YgShoppingCarModel> carList = ygShoppingCarService.
                findShoppingCarListBySkuIds(skuIds, userId, distribution, salesPlatform);
        if (carList == null) {
            return Message.error("购物车中没有skuid = " + Arrays.toString(skuIds) + "的商品", null);

        }
        Message jiaJiaGouMsg = this.validateJiaJiaGou(carList,salesPlatform);
        if (!jiaJiaGouMsg.getType().equals(Message.Type.success)) {
            return jiaJiaGouMsg;
        }
        Message validateManZeng = this.validateManZeng(carList,salesPlatform);
        if (!validateManZeng.getType().equals(Message.Type.success)) {
            return validateManZeng;
        }
        ygShoppingCarService.updateCarForCheck(skuIds, userId, salesPlatform);
        return Message.success(null);

    }
}
